package com.power.sifa.supervise.dao;


import com.power.sifa.supervise.model.Apl_supervise;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

/**
 * 复议监督主表 持久层(hibernate)
 */

public interface Apl_superviseDao extends JpaRepository<Apl_supervise, Serializable>, JpaSpecificationExecutor<Apl_supervise>, Repository<Apl_supervise, Serializable>, Apl_superviseDaoCustom<Apl_supervise, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Apl_supervise s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);


   /**
    * 更新案件的第一第二承办人
    * @param id
    * @param firstid
    * @param firstname
    * @param secondid
    * @param secondname
    * @param thirdid
    * @param thirdname
    */
   @Modifying
   @Transactional
   @Query(value = "update Apl_supervise s set s.firstid = :firstid, s.firstname = :firstname, s.secondid = :secondid, s.secondname = :secondname, s.thirdid = :thirdid, s.thirdname = :thirdname where  s.id = :id ", nativeQuery = true)
   void updateFirstAndSecondPerson(@Param("id") String id, @Param("firstid") String firstid, @Param("firstname") String firstname,
                                   @Param("secondid") String secondid, @Param("secondname") String secondname, @Param("thirdid") String thirdid, @Param("thirdname") String thirdname);


   /**
    * 重新设置id
    * @param id
    */
   @Modifying
   @Transactional
   @Query(value = "update Apl_supervise s set s.firstid = null, s.firstname = null, s.secondid = null, s.secondname = null, s.thirdid = null, s.thirdname = null where  s.id = :id ", nativeQuery = true)
   void resetFirstAndSecondPerson(@Param("id") String id);

   /**
    * 更新案件的完成状态
    * @param id
    * @param isFinish
    */
   @Modifying
   @Transactional
   @Query(value = "update Apl_supervise s set s.isfinish = :isFinish where  s.id = :id ", nativeQuery = true)
   void updateFinishState(@Param("id") String id, @Param("isFinish") Integer isFinish);
}
